package com.chenfan.process.entity.vo;

import com.chenfan.ccp.plug.mybatis.annotation.Column;
import com.chenfan.process.entity.po.ProcessDetailPo;
import com.chenfan.process.enums.ProcessResultTypeEnums;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @author pengjian
 * @date 2021/1/25
 * 执行过程
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProcessDetailVo {

    /**
     * 执行过程的Id,修改或者查询的需要
     */

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /**
     * 是否是多样,false不是，true是默认值不是
     */

    private Boolean multiple;

    /**
     * 父级的Id,默认为0
     */

    @ApiModelProperty("审批实例ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;

    /**
     * 执行的任务的Id
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long processId;

    /**
     * 下个节点的ID
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long nextProcessId;
    /**
     * 过程的状态,参考 {@link ProcessResultTypeEnums}
     */

    private Integer resultType;

    @ApiModelProperty("状态值")
    private String resultTypeValue;

    public String getResultTypeValue() {
        if (StringUtils.isNoneBlank(resultTypeValue)) {
            return resultTypeValue;
        }
        return ProcessResultTypeEnums.getMessage(resultType);
    }

    /**
     * 执行人的用户ID
     */
    @ApiModelProperty("审批人名称")
    private String executorUserId;

    /**
     * 执行人的名称
     */
    @ApiModelProperty("审批人名称")
    private String executorUserName;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty("意见")
    private String remark;

    @ApiModelProperty("审批模板ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long approvalTemplateId;
    
    @Column(commit = "更新人名称")
    private String updateName;

    @ApiModelProperty("分组id")
    private Long groupId;

    public ProcessDetailPo copyProcessDetailPo() {
        ProcessDetailPo po = new ProcessDetailPo();
        org.springframework.beans.BeanUtils.copyProperties(this, po);
        return po;
    }
}
